<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Jobs_model extends MY_Model
{

	public function getJobsList($data = array(),$per_page, $limit){
        
        $where = " ";
        if(!empty($data['starttime'])){
            $where .= " AND publishtime >= {$data['starttime']}";
        }
        if(!empty($data['endtime'])){
            $data['endtime'] = $data['endtime']+3600*24;
            $where .= " AND publishtime <= {$data['endtime']}";
        }
        if(!empty($data['keyword'])){
            $where .= " AND content like '%{$data['keyword']}%'";
        }
       
        if(!empty($data['content'])){
            $where .= " AND r.content like '%{$data['content']}%'";
        }
       

        $limit = " limit {$per_page},{$limit}";

        $sql = "SELECT *  FROM blues_jobs  WHERE  isDel<>1  {$where}  ORDER BY sort DESC, publishtime DESC {$limit} ";
        $query = $this->db->query($sql);
        $result =$query->result_array();
        return $result;
    }


    public function getJobsCnt($data = array()){
        $where = " ";
        if(!empty($data['starttime'])){
            $where .= " AND publishtime >= {$data['starttime']}";
        }
        if(!empty($data['endtime'])){
            $data['endtime'] = $data['publishtime']+3600*24;
            $where .= " AND publishtime <= {$data['endtime']}";
        }
        if(!empty($data['keyword'])){
            $where .= " AND content like '%{$data['keyword']}%'";
        }
       
        if(!empty($data['content'])){
            $where .= " AND r.content like '%{$data['content']}%'";
        }
        
        
        $sql = "SELECT * FROM blues_jobs WHERE isDel=0  {$where}  ";
        $query = $this->db->query($sql);
        return $query->num_rows();
    }


     //编辑
    public function editJobs($id,$data = array()){
        if($id){
            $this->db->where("id",$id);
            $res = $this->db->update("blues_jobs",$data);
        }else{
            $res = $this->db->insert("blues_jobs",$data);
        }
        return $res;
    }

    public function delJobs($id){
        $this->db->where("id",$id);
        $data = array(
            'isDel'=>1
        );
        $res = $this->db->update("blues_jobs",$data);
        return $res;
    }

     //根据id获取广告信息
    public function getJobsInfobyID($id){
        $this->db->where("id",$id);
        $query = $this->db->get("blues_jobs");
        return $query->row_array();
    }


    public function editStatus($data = array()){

        $this->db->where("id",$data['id']);
        
        $updata['onlinestatus'] = $data['onlinestatus'];
		if($data['onlinestatus'] == 0)
		{
			$updata['ispublish'] = 0;
		}
       
        $res = $this->db->update("blues_jobs",$updata);
        return $res;
    }


}


